package it.uniroma2.art.owlart.langsearch.index.config;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.br.BrazilianAnalyzer;
import org.apache.lucene.analysis.cz.CzechAnalyzer;
import org.apache.lucene.analysis.de.GermanAnalyzer;
import org.apache.lucene.analysis.el.GreekAnalyzer;
import org.apache.lucene.analysis.fr.FrenchAnalyzer;
import org.apache.lucene.analysis.nl.DutchAnalyzer;
import org.apache.lucene.analysis.ru.RussianAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.util.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LanguageAnalysisConfiguration extends IndexingConfigurationAdapter implements
		IndexingConfiguration {
	
	protected static Logger logger = LoggerFactory.getLogger(LanguageAnalysisConfiguration.class);

	Version ver;
	
	LanguageAnalysisConfiguration(Version ver, String... languages) {
		super(languages);
		this.ver = ver;  
	}

	public Analyzer getAnalyzerForLabels(String lang) {
		logger.info("getting suitable Analyzer for lang: " + lang);
		if (lang.equalsIgnoreCase("br"))
			return new BrazilianAnalyzer(ver);
		// StandardAnalyzer is good for English, as it uses: StandardFilter, LowerCaseFilter and StopFilter
		if (lang.equalsIgnoreCase("en"))
			return new StandardAnalyzer(ver);
		// no analyzer for Italian
		if (lang.equalsIgnoreCase("it"))
			return new SimpleAnalyzer(ver);
		if (lang.equalsIgnoreCase("cn"))
			return new StandardAnalyzer(ver);
		if (lang.equalsIgnoreCase("cz"))
			return new CzechAnalyzer(ver);
		if (lang.equalsIgnoreCase("de"))
			return new GermanAnalyzer(ver);
		if (lang.equalsIgnoreCase("el"))
			return new GreekAnalyzer(ver);
		if (lang.equalsIgnoreCase("fr"))
			return new FrenchAnalyzer(ver);
		if (lang.equalsIgnoreCase("nl"))
			return new DutchAnalyzer(ver);
		if (lang.equalsIgnoreCase("ru"))
			return new RussianAnalyzer(ver);

		// SimpleAnalyzer is an Analyzer that filters LetterTokenizer with LowerCaseFilter.
		else
			return new SimpleAnalyzer(ver);
	}

	public boolean areLabelsTokenized() {
		return true;
	}

}
